<!--
 * @Author: cgl
 * @Date: 2023-04-18 15:12:26
 * @LastEditors: cgl
 * @LastEditTime: 2023-09-05 14:16:12
 * @FilePath: \public-health-emergencies-fed:\新放射\新radiation-hygiene-fe\src\views\slide\task.vue
 * @Description:
 *
 * Copyright (c) 2023 by cgl/微盛信息产业有限公司, All Rights Reserved.
-->
<template>
  <div class="app-container">
    <el-form
      class="searchform"
      :model="queryParams"
      ref="queryParams"
      size="small"
      label-width="80px"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="单位名称" prop="entrustOrganizationId">
            <entrustSelect
              :eid.sync="queryParams.entrustOrganizationId"
            ></entrustSelect>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="年份" prop="year">
            <el-date-picker v-model="date" type="year" placeholder="选择年">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="报告编号">
            <el-input
              v-model="queryParams.reportNumber"
              placeholder="请输入"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="20px">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getList()"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div class="tableoperation">
      <el-button
        type="primary"
        icon="el-icon-plus"
        size="mini"
        v-hasPermi="['task:personalDosimeter:add']"
        @click.native.prevent="openhandleDialog({}, 'add')"
        >添加</el-button
      >
      <el-button
        type="primary"
        icon="el-icon-plus"
        size="mini"
        v-hasPermi="['task:personalDosimeter:generate']"
        @click.native.prevent="openGenerateDialog({}, 'generate')"
        >批量生成</el-button
      >
    </div>

    <el-tabs v-model="queryParams.tasksState" @tab-click="getList" class="tab">
      <el-tab-pane label="待办理" name="0" v-if="isPer"></el-tab-pane>
      <el-tab-pane label="待审批" name="1"></el-tab-pane>
      <el-tab-pane label="已签发" name="2"></el-tab-pane>
    </el-tabs>
    <el-table
      :height="height - 443 + 'px'"
      v-loading="loading"
      :data="dataList"
      @row-dblclick="openhandleDialog($event, 'view')"
    >
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="报告编号" align="center" prop="reportNumber" />
      <el-table-column
        label="单位名称"
        align="center"
        prop="organizationName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="年份"
        align="center"
        prop="year"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="仪器名称"
        align="center"
        prop="equipmentName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="仪器型号"
        align="center"
        prop="equipmentTypeNumber"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="仪器编号"
        align="center"
        prop="equipmentNumber"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="是否打印" align="center" prop="isPrint">
        <template slot-scope="{ row }">
          <dict-tag
            :options="dict.type.is_or_no"
            :value="row.isPrint || 0"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="{ row }">
          <el-button
            v-hasPermi="['task:personalDosimeter:handle']"
            v-show="
              queryParams.tasksState == '0' ||
              (queryParams.tasksState == '1' && row.canAudit)
            "
            @click.native.prevent="openhandleDialog(row, 'handle')"
            type="text"
          >
            办理
          </el-button>
          <el-button
            v-show="row.recordOssId"
            @click.native.prevent="viewFile(row.recordOssId)"
            type="text"
          >
            记录
          </el-button>
          <el-button
            v-show="row.reportOssId"
            @click.native.prevent="viewFile(row.reportOssId, row)"
            type="text"
          >
            报告
          </el-button>
          <el-button
            v-if="queryParams.tasksState != '0'"
            @click.native.prevent="handleFlowRecord(row)"
            type="text"
          >
            流程
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <annualdose-dialog
      ref="annualdoseDialog"
      @close="this.getList"
    ></annualdose-dialog>
    <generate-dialog ref="generateDialogRefs" />
    <WorkFlow ref="workFlow"></WorkFlow>
  </div>
</template>

<script>
import { annualDoseList } from "@/api/slides/task";
import { annualDosePrintReport } from "@/api/slides/annualdose";
import annualdoseDialog from "./components/annualdose/Dialog.vue";
import GenerateDialog from "./components/annualdose/generateDialog.vue";
import { listByIds } from "@/api/system/oss";
import WorkFlow from "@/components/WorkFlow";
import entrustSelect from "@/components/select/src/entrustSelect";
export default {
  name: "annualdose",
  dicts: ["is_or_no"],
  components: { annualdoseDialog, WorkFlow, entrustSelect, GenerateDialog },
  data() {
    return {
      // 查询参数
      queryParams: {},
      queryParamsCache: {
        pageNum: 1,
        pageSize: 10,
        tasksState: "0",
        year: null,
      },
      entrustOrganization: null,
      total: 0,
      height: document.documentElement.clientHeight,
      dataList: [],
      loading: false,
      entrustOrganizationSelect: [],
      entrustOrganizationSelectCache: null,
    };
  },
  computed: {
    date: {
      get() {
        return this.queryParams.year
          ? new Date(this.queryParams.year + "-01-01")
          : null;
      },
      set(val) {
        this.queryParams.year = val ? val.getFullYear() : null;
      },
    },
  },
  created() {
    // 未发起栏的权限控制（领导层没有）
    let permissions = this.$store.getters.permissions;
    let found = permissions.find((item) => {
      return item == "task:personalDosimeter:handle";
    });
    this.isPer =
      found == "task:personalDosimeter:handle" || permissions == "*:*:*";
    this.queryParams = JSON.parse(JSON.stringify(this.queryParamsCache));
    // 获取列表
    this.getList();
  },
  methods: {
    reset() {
      let tasksState = this.queryParams.tasksState;
      this.queryParams = JSON.parse(JSON.stringify(this.queryParamsCache));
      this.queryParams.tasksState = tasksState;
      this.getList();
    },
    // 查看流程
    handleFlowRecord(row) {
      this.$refs.workFlow.openDialog(row);
    },
    // 报告预览
    viewFile(ossId, row) {
      row && this.setPrintReport(row.id);
      listByIds(ossId).then((response) => {
        window.open(response?.data[0]?.url, "PDF", "");
      });
    },
    getList() {
      this.loading = true;
      annualDoseList(this.queryParams)
        .then((response) => {
          this.dataList = response.rows || [];
          this.total = response.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    setPrintReport(id) {
      annualDosePrintReport({
        id,
      }).then((res) => {
        this.getList();
      });
    },
    openhandleDialog(row, type) {
      this.$refs["annualdoseDialog"].open(row.id, type);
    },
    openGenerateDialog(row) {
      this.$refs["generateDialogRefs"].open(row.id);
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  display: flex;
  flex-direction: column;
}
</style>
